package com.war.dao.stock;

import com.war.pojo.stock.DamagesInfo;
import com.war.pojo.stock.TransferInfo;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;

@Mapper
public interface TransferDao {

    //1 完成对货品调拨的录入，删除，修改，查看详情功能
    @Insert("INSERT INTO stock_transfer(" +
            "product_name,in_warehouse_name,in_num," +
            "out_warehouse_name,out_num,unit,in_warehouse_manager," +
            "out_warehouse_manager,operator_id,operate_time,id,transfer_reason) VALUES(" +
            "#{product_name},#{in_warehouse_name},#{in_num},#{out_warehouse_name}," +
            "#{out_num},#{unit}," +
            "(SELECT name FROM sys_user WHERE id=(SELECT manager FROM sys_warehouse WHERE name=#{in_warehouse_name}))," +
            "(SELECT name FROM sys_user WHERE id=(SELECT manager FROM sys_warehouse WHERE name=#{out_warehouse_name}))," +
            "'123'" +//用户id  后续从session中获取
            ",NOW(),UNIX_TIMESTAMP(NOW())+RAND()*10000,#{transfer_reason})")
    int add(TransferInfo transferInfo);



    @Delete("DELETE FROM stock_transfer WHERE id=#{id}")
    int deleteById(TransferInfo transferInfo);


    @Update("UPDATE stock_transfer SET " +
            "product_name=#{product_name}," +
            "in_warehouse_name=#{in_warehouse_name}," +
            "in_num=#{in_num}," +
            "out_warehouse_name=#{out_warehouse_name}," +
            "out_num=#{out_num}," +
            "in_warehouse_manager=(SELECT name FROM sys_user WHERE id=(SELECT manager FROM sys_warehouse WHERE name=#{in_warehouse_name}))," +
            "out_warehouse_manager=(SELECT name FROM sys_user WHERE id=(SELECT manager FROM sys_warehouse WHERE name=#{out_warehouse_name}))," +
            "unit=#{unit}," +
            "transfer_reason=#{transfer_reason}" +
            " WHERE id=#{id}")
    int updateById(TransferInfo transferInfo);


    @Select("select * from stock_transfer")
    List<TransferInfo> selectAll();

    @Select("select * from stock_transfer where product_name=#{conValue}")
    List<TransferInfo> selectByProductName(TransferInfo transferInfo);

    @Select("select * from stock_transfer where in_warehouse_name=#{conValue}")
    List<TransferInfo> selectByInWareName(TransferInfo transferInfo);

    @Select("select * from stock_transfer where out_warehouse_name=#{conValue}")
    List<TransferInfo> selectByOutWareName(TransferInfo transferInfo);

    @Select("select * from stock_transfer where id=#{id}")
    List<TransferInfo> selectById(TransferInfo transferInfo);

    //报表
    @Select("SELECT product_name,out_num FROM stock_transfer")
    List<TransferInfo> transfer_num_data();
}
